home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / Apple Script / OSAX / Finder Scripting Toolkit v1.0 / fwin coercion osax / alis2fwin.c < prev    next >
Text File  |  1993-07-20  |  1KB  |  63 lines

  1. /*
  2.  
  3.         F W I N   C O E R C I O N   O S A X
  4.         
  5.         Version 1.0
  6.         Freeware by Daniel Ranson
  7.         
  8.         This osax performs coercions to the FinderWindow (fwin) record
  9.         type used by Finder events.
  10.         
  11.         There are actually three osax. This one converts aliases.
  12.  
  13. */
  14.  
  15. #include <Types.h>
  16. #include <Memory.h>
  17. #include <Aliases.h>
  18. #include <AppleEvents.h>
  19. #include <AERegistry.h>
  20.  
  21. struct FinderWindow{
  22.     long        windowType;
  23.     DescType    aliasType;
  24.     long        aliasLength;
  25.     AliasRecord    alias;
  26. };
  27.  
  28. typedef struct FinderWindow FinderWindow;
  29.  
  30. pascal OSErr ALIS2FWIN(    DescType    fromType,
  31.                         Ptr            dataPtr,
  32.                         Size        dataSize,
  33.                         DescType    toType,
  34.                         long        refCon,
  35.                         AEDesc        *result)
  36. {
  37. #pragma unused(fromType, toType, refCon)
  38.  
  39.     FinderWindow    **hFwin;
  40.     Size            sizH;
  41.     OSErr            err;
  42.     
  43.     /* Allocate the structure */
  44.     sizH = sizeof(FinderWindow) + dataSize - sizeof(AliasRecord);
  45.     hFwin = (FinderWindow**)NewHandle(sizH);
  46.     if (hFwin == 0) return errAECoercionFail;
  47.     
  48.     /* Fill in fields */
  49.     (**hFwin).windowType = 0;
  50.     (**hFwin).aliasType = typeAlias;
  51.     (**hFwin).aliasLength = dataSize;
  52.     BlockMove(dataPtr, &((**hFwin).alias), dataSize);
  53.     
  54.     /* Create the descriptor */
  55.     MoveHHi((Handle)hFwin);
  56.     HLock((Handle)hFwin);
  57.     err = AECreateDesc(typeFinderWindow, (Ptr)(*hFwin), sizH, result);
  58.     
  59.     /* Clean up */
  60.     DisposeHandle((Handle)hFwin);
  61.     return err;
  62. }
  63.